package icegps.com.pingdj.map.draw;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;

import icegps.com.pingdj.App;
import icegps.com.pingdj.map.bean.MapStatus;

import static icegps.com.pingdj.map.MapManager.windowHeight;
import static icegps.com.pingdj.map.MapManager.windowWidth;
import static icegps.com.pingdj.map.count.ScreenCount.getScreenCxByTx;
import static icegps.com.pingdj.map.count.ScreenCount.getScreenCyByTy;


/**
 * Created by 111 on 2018/3/5.
 */

public class DrawLine {
    private Paint linePint;
    private MapStatus mapStatus;
    private int DIST = 50;
    private float multiple;

    public DrawLine(MapStatus mapStatus) {
        this.mapStatus = mapStatus;
        linePint = new Paint();
        linePint.setColor(Color.parseColor("#663F51B5"));
        linePint.setPathEffect(new DashPathEffect(new float[]{5, 5}, 0));

    }

    public void drawLine(Canvas canvas) {
        multiple = mapStatus.getMultiple();
        drawHLine(canvas);
        drawVLine(canvas);
    }


    /**
     * @param canvas 以竖向屏幕中心点为基准点,绘制一条横线,尔后以基准点为中心,向上下扩散
     */
    private void drawHLine(Canvas canvas) {
        int countX = (windowHeight / DIST + 1);
        float startX = 0;
        float stopX = startX + windowWidth;
        for (int i = 0; i < countX; i++) {
            canvas.drawLine(startX, i * DIST, stopX, i * DIST, linePint);
        }

    }


    private void drawVLine(Canvas canvas) {
        int countY = (windowWidth / DIST + 1);
        float startY = 0;
        float stopY = startY + windowHeight;
        for (int i = 0; i < countY; i++) {
            canvas.drawLine(i * DIST, startY, i * DIST, stopY, linePint);
        }
    }

}
